import { apiClient } from '../config'
import type {
  GetMenuListAsyncParams,
  MenuListResponse,
  AddMenuAsyncParams,
  Response,
  UpdateMenuAsyncParams,
  GetDynamicRouterAsyncParams,
} from '../../types/Menu'

/**
 * 查询菜单列表
 * @returns 菜单列表响应
 */
export const getMenuListAsync = async (
  params: GetMenuListAsyncParams,
): Promise<MenuListResponse> => {
  return await apiClient.get('/Menu/GetMenuListAsync', { params })
}

/**
 * 获取一级菜单
 * @returns 一级菜单列表响应
 */
export const getOneMenuList = async (): Promise<Response> => {
  return await apiClient.get('/Menu/GetOneMenuList')
}

/**
 * 添加目录/菜单
 * @returns
 */
export const addMenuAsync = async (params: AddMenuAsyncParams): Promise<Response> => {
  return await apiClient.post('/Menu/AddMenuAsync', params, {
    headers: {
      'Content-Type': 'application/json',
    },
  })
}

/**
 * 修改目录/菜单
 * @returns
 */
export const updateMenuAsync = async (params: UpdateMenuAsyncParams): Promise<Response> => {
  return await apiClient.post('/Menu/UpdateMenuAsync', params, {
    headers: {
      'Content-Type': 'application/json',
    },
  })
}

/**
 * 动态菜单
 * @returns 动态菜单响应
 */
export const getDynamicRouterAsync = async (
  params: GetDynamicRouterAsyncParams,
): Promise<Response> => {
  return await apiClient.get('/Menu/GetDynamicRouterAsync', { params })
}

export default {
  getMenuListAsync,
  getOneMenuList,
  addMenuAsync,
  getDynamicRouterAsync,
}
